﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MsTestUtilities.RowTests;
using MsTestUtilities.Utilities;

namespace MsTestUtilitiesTests.RowTests.ExpectorTests
{
    [TestClass]
    public class EqualityExpectations
    {
        private TestCase<int, int> _testCase;
        private Expector<int, int> _expector;

        [TestInitialize]
        public void Setup()
        {
            _testCase = new TestCase<int, int>(null);
            _expector = new Expector<int, int>(null, _testCase);
        }

        [TestMethod]
        public void ExpectationHoldsOnEquality()
        {
            _expector.Expect(42);
            AssertExpectationIsValidFor(() => 42);
        }

        [TestMethod]
        public void ExpectationFailsOnInequality()
        {
            _expector.Expect(42);
            AssertExpectationFailsFor(() => 0);
        }

        private void AssertExpectationIsValidFor(Func<int> action)
        {
            Assert.IsTrue(GetAssertionResult(action));
        }

        private void AssertExpectationFailsFor(Func<int> action)
        {
            Assert.IsFalse(GetAssertionResult(action));
        }

        private bool GetAssertionResult(Func<int> action)
        {
            return _testCase.Expectation.IsSatisfiedFor(action).AssertionHolds;
        }
    }
}
